package main

import (
	"flag"
	"fmt"
	"github.com/fcbox/dbreplay/dbreplay-server/record"
	"os"
	"runtime"
)

type KeyCount struct {
	key   string
	count int
}

func init() {
	flag.Parse()
}

var (
	ip                            = flag.String("ip", "127.0.0.1", "the ip of need to catch.")
	port                          = flag.Int("port", 3306, "the port to need to catch.")
	cpu							  = flag.Int("cpu", 2, "the max cpu nums.")
	tip                            = flag.String("tip", "10.204.52.151", "the ip of need to replay.")
	tport                          = flag.Int("tport", 3306, "the port to need to replay.")
	tuser						  = flag.String("tuser","pushserver","the database user.")
	tpassword					  = flag.String("tpass","pushserver123.com","the database password.")
	tdb					 		  = flag.String("tdb","test","the default database .")
	tfileName					  = flag.String("tfile","info.log","the replay file .")
	speed						  = flag.Int("speed",1,"the speed of bench")
	replay						  = flag.Int("replay",0,"replay with record")
	fileName		string = "info.log"
	errFileName		string = "error.log"
)

func main() {
	flag.Parse()
	runtime.GOMAXPROCS(*cpu)
	recon := initRecordConf()
	err := recon.Watch()
	if err != nil{
		fmt.Println(err.Error())
	}
}

func initRecordConf() *record.RecordConf {
	recon := record.NewRecordConf()
	recon.Ip = *ip
	recon.Port = * port
	recon.Replay = * replay
	recon.Speed = * speed
	recon.Tdb = * tdb
	recon.Tip = * tip
	recon.Tpassword = * tpassword
	recon.Tport = * tport
	recon.Tuser = * tuser
	recon.FileObj,_ = os.OpenFile(fileName,os.O_RDWR|os.O_CREATE|os.O_APPEND,0644)
	recon.ErrFileObj,_ = os.OpenFile(errFileName,os.O_RDWR|os.O_CREATE|os.O_APPEND,0644)
	return recon
}